class AuthException implements Exception {
  AuthException({
    required this.logMessage,
    StackTrace? stackTrace,
    this.error,
  }) : stackTrace = stackTrace ?? StackTrace.current;

  factory AuthException.withoutToken({Object? error}) => AuthException(
        logMessage: '本地没有Token',
        error: error,
      );

  factory AuthException.requestError({Object? error}) => AuthException(
        logMessage: '请求错误',
        error: error,
      );

    factory AuthException.unauthorized({Object? error}) => AuthException(
        logMessage: '未授权，需要重新登录',
        error: error,
      );

  /// 打印在日志里的内容
  final String logMessage;

  /// 错误的内容
  final Object? error;

  /// 日志堆栈
  final StackTrace stackTrace;

  @override
  String toString() {
    return 'AuthException: $logMessage\nError: $error';
  }
}
